package com.y.ari.controller;

import com.y.ari.common.RestResponse;
import com.y.ari.dto.OrdersFormDTO;
import com.y.ari.dto.OrdersSelDTO;
import com.y.ari.dto.PageDTO;
import com.y.ari.entity.PageParams;
import com.y.ari.service.OrdersService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 订单信息 前端控制器
 * </p>
 *
 * @author itcast
 */
@Slf4j
@RestController
@RequestMapping("/orders")
public class OrdersController {

    @Autowired
    private OrdersService ordersService;


    @PostMapping("/add")
    public RestResponse addOrder(@RequestBody OrdersFormDTO ordersFormDTO) {
        return ordersService.addOrder(ordersFormDTO);
    }

    @PutMapping("/pay/{id}")
    public RestResponse payOrder(@PathVariable Long id) {
        return ordersService.payOrder(id);
    }

    @PostMapping("/sel")
    public RestResponse selOrders() {
        List<OrdersSelDTO> orders = ordersService.selOrders();
        return RestResponse.success(orders, "");
    }

    @PutMapping("/mo/{id}")
    public RestResponse mOrder(@PathVariable Long id) {
        return ordersService.mOrder(id);
    }

    @DeleteMapping("/del/{id}")
    public RestResponse delOrder(@PathVariable Long id) {
        return ordersService.delOrder(id);
    }


    /**
     * 管理端订单查询
     *
     * @return
     */
    @PostMapping("/selM")
    public RestResponse selOrdersM(@RequestBody PageParams pageParams) {
        PageDTO pageDTO = ordersService.selOrdersM(pageParams);
        return RestResponse.success(pageDTO, "");
    }
}
